package com.mostsnails.common.base.constant;

import java.io.Serializable;

/**
 * 封装返回结果
 *
 * @Author MostSnails
 * @Version 1.0
 */
public class R<T> implements Serializable {
    private Long code;

    private T data;

    public static <T> R<T> ok(T t) {
        return new R<T>(ResultCodeEnum.SUCCESS.getCode(), t);
    }

    public static R ok() {
        return new R(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getName());
    }

    public static R error() {
        return new R(ResultCodeEnum.FAILED.getCode(), ResultCodeEnum.FAILED.getName());
    }

    public static <T> R<T> error(T t) {
        return new R<T>(ResultCodeEnum.FAILED.getCode(), t);
    }

    public R() {
    }

    public R(T data) {
        this.data = data;
    }

    public R(Long code, T data) {
        this.code = code;
        this.data = data;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
